package com.yugao.fintech.antelope.mps.listener;

import com.yugao.fintech.antelope.base.config.core.event.ConfigDeleteEvent;
import com.yugao.fintech.antelope.base.config.core.event.ConfigRefreshEvent;
import com.yugao.fintech.antelope.base.model.module.config.ConfigInfo;
import com.yugao.fintech.antelope.mps.core.channel.ChannelClientManager;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;

@Slf4j
@RequiredArgsConstructor
@Component
public class MsgPushClientConfigEventListener {
    @Autowired
    private ChannelClientManager clientManager;

    @EventListener(ConfigDeleteEvent.class)
    public void delete(ConfigDeleteEvent event) {
        Object configKey = event.getSource();
        clientManager.deleteChannelClient(String.valueOf(configKey));
        log.debug("configKey [{}] 被删除", configKey);
    }

    @EventListener(ConfigRefreshEvent.class)
    public void refresh(ConfigRefreshEvent event) {
        ConfigInfo configInfo = (ConfigInfo) event.getSource();
        clientManager.updateChannelClient(configInfo);
        log.debug("configKey [{}] 被刷新", configInfo);
    }
}
